package org.csc.sss.util;

import java.util.HashMap;
import java.util.Map;

public class Result<T> {


    private int code;
    private String msg;
    private T attach;

    public Result(int code, String msg, T attach) {
        this.code = code;
        this.msg = msg;
        this.attach = attach;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getAttach() {
        return attach;
    }

    public void setAttach(T attach) {
        this.attach = attach;
    }

    public static enum ResultCode {
        OK(200, "请求成功"),
        ERROR(400, "请求参数错误"),
        FAIL(500, "服务器内部错误"),
        INSERT_DATA_ERROR(5001, "插入数据失败"),
        DELETE_DATA_ERROR(5002, "删除数据失败"),
        UPDATE_DATA_ERROR(5003, "更新数据失败"),
        SELECT_NO_DATA(5004, "数据不存在");

        private int code;
        private String value;

        ResultCode(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public String getValue() {
            return value;
        }

        public static ResultCode getByValue(int code) {
            for (ResultCode resultCode : ResultCode.values()) {
                if (resultCode.getCode() == code) {
                    return resultCode;
                }
            }
            return null;
        }
    }
}
